﻿//====================================================================
// Create by Daniel
// file： Log.cs
// project ：Utility Class
// Build time：2012-8-8
// modify:
// description:
// ===================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace YunCMS.Common
{
    public class LogUtil
    {
        private static string file = @"simple.log";

        /// <summary>
        /// Write log in file.
        /// </summary>
        /// <param name="msg"></param>
        public static void WriteLog(string msg)
        {
            StreamWriter writer = null;
            string fileName = IOUtil.GetMapPath(file);
            try
            {
                if (!File.Exists(fileName))
                {
                    File.Create(fileName).Close();
                }
                writer = File.AppendText(fileName);
                writer.WriteLine("{0} --- {1}", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss fff"), msg);
                writer.Flush();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }

        /// <summary>
        /// Write log in console.
        /// </summary>
        /// <param name="msg"></param>
        public static void WriteConsoleLog(object msg)
        {
            Debug.WriteLine("{0} --- {1}", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss fff"), msg.ToString());
        }
    }
}
